<template>
  <div class="order">
    <div class="top">
      <i class="el-icon-arrow-left" @click="goBack" style="z-index:20"></i>
      <div class="title">我的订单</div>
    </div>
    <div class="content">
      <div class="o-list">
        <div v-for="order in orders" class="o-item" @click="getDetail(order)">
          <div class="tip">
            <div class="send-type" v-if="order.send_type === 1">自提</div>
            <div :class="[order.state === 1?'state-a':'state']" >{{order.state === 1? '已完成':'已关闭'}}</div>
          </div>
          <div>
            <div class="time">{{order.created_at}}</div>
            <div v-for="(sub,index) in order.order_sub" class="s-lis" v-if="index<2">
              <div>{{sub.goods_info.name}}</div>
              <div>x{{sub.count}}</div>
            </div>
            <div v-if="order.order_sub.length>2">...</div>
            <div class="count-price">共{{order.order_sub.length}}件商品，实付 <span>￥{{order.fee_goods_sum}}</span></div>
          </div>
        </div>

      </div>
      <div class="noOrder" v-if="orders.length<1"><i class="el-icon-sold-out"></i>暂时没有订单</div>
    </div>
    <v-detail :showFlag="showFlag" :order="order"></v-detail>
  </div>
</template>

<script>
  import {_post} from '@/api/mainApi';
  import detail from './detail/detail';

  export default {
    name: 'order',
    created() {
      console.log('params', this.$router.params);
      this.$root.eventHub.$on('o.del.close', this.close);
      this.getOrder();
    },
    components: {
      'v-detail': detail
    },
    computed: {

    },
    methods: {
      goBack() {
        this.$router.go(-1);
      },
      getDetail(order) {
        this.showFlag = true;
        this.order = order;
      },
      getOrder() {
        _post('frontend/order/index', {}).then(res => {
          console.log('res', res);
          const data = res.data;
          if (data.code === 200) {
            this.orders = data.data.data;
          }
        });
      },
      close() {
        this.showFlag = false;
      }
    },
    data() {
      return {
        orders: [],
        picurl: this.GLOBAL.picurl,
        showFlag: false,
        order: {}
      };
    }
  };
</script>

<style scoped>
  .order {
    display: flex;
    flex-flow: column;
    width: 100%;
    height: 100%;
  }

  .tip {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .state {
    font-size: 12px;
    color: #fff;
    padding: 5px;
    background: #d4d6d9;
    border-radius: 4px;
  }
  .state-a {
    font-size: 12px;
    color: #fff;
    padding: 5px;
    background: #35c865;
    border-radius: 4px;
  }

  .top {
    display: flex;
    align-items: center;
    height: 40px;
    border-bottom: 1px solid #d4d6d9;
  }

  .top i {
    font-size: 20px;
    font-weight: bolder;
    margin-left: 10px;
  }

  .top .title {
    position: absolute;
    display: flex;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    justify-content: center;
    align-items: center;
    height: 40px;
    line-height: 40px;
  }

  .content {
    position: relative;
    flex: 1;
    min-height: 400px;
  }

  .noOrder {
    position: relative;
    color: #c0c2c5;
    text-align: center;
    top: 200px;
  }

  .o-list {
    margin-top: 10px;
    padding: 0 10px;

  }

  .o-item {
    border-bottom: 1px solid #d9dde1;
    margin-top: 10px;
  }

  .o-list .is-active {
    color: #dcc379 !important;
  }

  .send-type {
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    width: 50px;
    background: #dcc379;
    border-radius: 50px;
    padding: 2px 0px;
    font-size: 14px;
  }

  .o-list .time {
    font-size: 12px;
    color: #d9dde1;
    margin: 10px 0;
  }

  .s-lis {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px 0;
    font-size: 13px;
  }

  .count-price {
    display: flex;
    justify-content: flex-end;
    align-self: center;
    color: #4d555d;
    font-size: 14px;
    margin: 10px 0;
  }

  .count-price span {
    color: #de0000;
  }
</style>
